00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef EXPORTLOAD33_HPP_
00016 #define EXPORTLOAD33_HPP_
00017
00018 #include <iostream>
00019 #include <string>
00020 #include <vector>
00021 #include <map>
00022
00023 #include "gridpack/parallel/communicator.hpp"
00024 #include "gridpack/component/data_collection.hpp"
00025 #include "gridpack/parser/dictionary.hpp"
00026 #include "gridpack/network/base_network.hpp"
00027 #include "gridpack/export/base_export.hpp"
00028
00029 namespace gridpack {
00030 namespace expnet {
00031
00032 template <class _network>
00033 class ExportLoad33
00034 {
00035 public:
00036
00037
00038
00039
00040 explicit ExportLoad33(boost::shared_ptr<_network> network) :
00041 p_network(network), p_comm(network->communicator())
00042 {
00043 }
00044
00045
00046
00047
00048 virtual ~ExportLoad33(){}
00049
00050
00051
00052
00053
00054
00055
00056
00057 void writeLoadBlock(std::ofstream &fout)
00058 {
00059 BaseExport<_network> exprt(p_comm);
00060 int me = p_comm.rank();
00061
00062 int nbus = p_network->numBuses();
00063 gridpack::component::DataCollection *data;
00064 int i, j;
00065 char buf[MAX_STRING_SIZE];
00066 std::vector<text_line> text_data;
00067 double pl, ql;
00068 for (i=0; i<nbus; i++) {
00069 if (p_network->getActiveBus(i)) {
00070 data = p_network->getBusData(i).get();
00071 double rval;
00072 int ival;
00073 std::string sval;
00074 char *ptr;
00075 int nload = 0;
00076 data->getValue(LOAD_NUMBER,&nload);
00077 for (j=0; j<nload; j++) {
00078 ptr = buf;
00079 ival = p_network->getOriginalBusIndex(i);
00080 data->getValue(LOAD_BUSNUMBER,&ival,j);
00081 sprintf(ptr,"%d,",ival);
00082 ptr += strlen(ptr);
00083 data->getValue(LOAD_ID,&sval,j);
00084 sprintf(ptr," \'%s\',",sval.c_str());
00085 ptr += strlen(ptr);
00086 ival = 1;
00087 data->getValue(LOAD_STATUS,&ival,j);
00088 sprintf(ptr," %d,",ival);
00089 ptr += strlen(ptr);
00090 ival = 1;
00091 if (!data->getValue(LOAD_AREA,&ival,j)) {
00092 data->getValue(BUS_AREA,&ival);
00093 }
00094 sprintf(ptr," %d,",ival);
00095 ptr += strlen(ptr);
00096 ival = 1;
00097 if (!data->getValue(LOAD_ZONE,&ival,j)) {
00098 data->getValue(BUS_ZONE,&ival);
00099 }
00100 sprintf(ptr," %d,",ival);
00101 ptr += strlen(ptr);
00102 rval = 0.0;
00103 data->getValue(LOAD_PL,&pl,j);
00104 sprintf(ptr," %f,",pl);
00105 ptr += strlen(ptr);
00106 rval = 0.0;
00107 data->getValue(LOAD_QL,&ql,j);
00108 sprintf(ptr," %f,",ql);
00109 ptr += strlen(ptr);
00110 if (pl == 0.0 && ql == 0.0) continue;
00111 rval = 0.0;
00112 data->getValue(LOAD_IP,&rval,j);
00113 sprintf(ptr," %f,",rval);
00114 ptr += strlen(ptr);
00115 rval = 0.0;
00116 data->getValue(LOAD_IQ,&rval,j);
00117 sprintf(ptr," %f,",rval);
00118 ptr += strlen(ptr);
00119 rval = 0.0;
00120 data->getValue(LOAD_YP,&rval,j);
00121 sprintf(ptr," %f,",rval);
00122 ptr += strlen(ptr);
00123 rval = 0.0;
00124 data->getValue(LOAD_YQ,&rval,j);
00125 sprintf(ptr," %f,",rval);
00126 ptr += strlen(ptr);
00127 ival = 1;
00128 if (!data->getValue(LOAD_OWNER,&ival,j)) {
00129 data->getValue(BUS_OWNER,&ival);
00130 }
00131 sprintf(ptr," %d,",ival);
00132 ptr += strlen(ptr);
00133 sprintf(ptr," 1, 0\n");
00134 text_line text;
00135 strcpy(text.text,buf);
00136 text.global_idx = p_network->getGlobalBusIndex(i);
00137 text.device_idx = j;
00138 text_data.push_back(text);
00139 }
00140 }
00141 }
00142 if (me == 0) {
00143 fout << "0 / END BUS DATA, BEGIN LOAD DATA" << std::endl;
00144 }
00145 exprt.writeDataBlock(fout, text_data);
00146 }
00147
00148 private:
00149 boost::shared_ptr<_network> p_network;
00150
00151 gridpack::parallel::Communicator p_comm;
00152 };
00153
00154 }
00155 }
00156
00157 #endif